﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BXH.Movie.FrmUsers;
using BXH.Movie.Model;
using System.IO;

namespace BXH.Movie.Forms
{
    public partial class UCMovieMain : UserControl
    {
        //private static string BasePath = AppDomain.CurrentDomain.BaseDirectory + "Images\\";
        private int ImageIndex = 0;

        public List<MovieInfoDto> Movies { set; private get; }
        public UCMovieMain()
        {
            InitializeComponent();
            this.flowLayoutPanel1.VerticalScroll.Visible = true;
        }

        private void CheckMovieInfo_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < Movies.Count(); i++)
            {
                var movieInfo = Movies[i];
                UCTicket uCTicket = new UCTicket(movieInfo);
                uCTicket.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                uCTicket.Location = new System.Drawing.Point(3, 4);
                uCTicket.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
                uCTicket.Name = "ucTicket1";
                uCTicket.Size = new System.Drawing.Size(160, 250);
                uCTicket.TabIndex = i;
                if (movieInfo.Image != null) {
                    var imagePath = Path.Combine(FrmMain.BasePath, movieInfo.Image);
                    if (File.Exists(imagePath))
                    {
                        uCTicket.SetImage(imagePath);
                    }
                    else
                    {
                        uCTicket.SetImage(Path.Combine(FrmMain.BasePath, "default.jpg"));
                    }
                }
                else
                {
                    uCTicket.SetImage(Path.Combine(FrmMain.BasePath,"default.jpg"));
                }

                uCTicket.SetName(movieInfo.Name);
                this.flowLayoutPanel1.Controls.Add(uCTicket);
            }

            if (FrmMain._FrmMain.ImageList != null && FrmMain._FrmMain.ImageList.Count > 0)
            {
                this.PicLogo.Image = FrmMain._FrmMain.ImageList[0];
                this.timer1.Enabled = true;
                this.timer1.Start();
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            PicLogo.Image = FrmMain._FrmMain.ImageList[ImageIndex];
            ImageIndex++;
            if (ImageIndex > FrmMain._FrmMain.ImageList.Count - 1) ImageIndex = 0;
        }
    }
}
